package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsTourismProjectActivitiesDetail;
import com.macro.mall.dto.BmsTourismProjectActivitiesParam;
import com.macro.mall.model.BmsTourismProjectActivities;
import com.macro.mall.service.BmsTourismProjectActivitiesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(tags = "BmsTourismProjectActivitiesController")
@Tag(name = "BmsTourismProjectActivitiesController", description = "文旅项目-活动")
@RequestMapping("/tourismProjectActivities")
public class BmsTourismProjectActivitiesController {

    @Autowired
    private BmsTourismProjectActivitiesService bmsTourismProjectActivitiesService;

    @ApiOperation("分页查询文旅项目-活动")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsTourismProjectActivities>> getList(@RequestBody BmsTourismProjectActivitiesParam bmsTourismProjectActivitiesParam) {
        List<BmsTourismProjectActivities> bmsTourismProjectActivitiesList = bmsTourismProjectActivitiesService.getList(bmsTourismProjectActivitiesParam);
        return CommonResult.success(CommonPage.restPage(bmsTourismProjectActivitiesList));
    }

    @ApiOperation("根据id获取文旅项目-活动信息")
    @RequestMapping(value = "/getListByTourismProjectId/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<?> getListByTourismProjectId(@PathVariable Long id) {
        return CommonResult.success(bmsTourismProjectActivitiesService.getListByTourismProjectId(id));
    }

    @ApiOperation("添加文旅项目-活动")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsTourismProjectActivitiesParam bmsTourismProjectActivitiesParam) {
        int count = bmsTourismProjectActivitiesService.create(bmsTourismProjectActivitiesParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改文旅项目-活动")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsTourismProjectActivitiesParam bmsTourismProjectActivitiesParam) {
        int count = bmsTourismProjectActivitiesService.update(bmsTourismProjectActivitiesParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("根据id获取文旅项目-活动信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsTourismProjectActivitiesDetail> getItem(@PathVariable Long id) {
        BmsTourismProjectActivitiesDetail bmsTourismProjectActivitiesDetail = bmsTourismProjectActivitiesService.getItem(id);
        return CommonResult.success(bmsTourismProjectActivitiesDetail);
    }

    @ApiOperation("删除文旅项目-活动")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsTourismProjectActivitiesService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
